package com.learng.springcloud.service;

import com.learng.springcloud.entity.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * Created by zhouwei on 2020/7/22.
 */
@Service
public class MemberRestTemplateService {

    @Autowired(required = false)
    RestTemplate restTemplate;

    public List<Member> getAll(){
        ParameterizedTypeReference<List<Member>> responseType = new ParameterizedTypeReference<List<Member>>(){};
        ResponseEntity<List<Member>> resp = restTemplate.exchange("http://member-service/member/getAll",
                HttpMethod.GET, null, responseType);
        List<Member> list = resp.getBody();
        return list;
    }

}
